#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int MAXN = 1e5 + 1000;

int base[MAXN], c[MAXN], d[50][MAXN], a[MAXN];

int getans(int r, int g){
    if(r == 1){
        if(d[r][g] == 0){
            if(a[2 * g - 1] >= r) return 2 * g - 1;
            else return 2 * g;
        }
        else{
            if(a[2 * g] >= r) return 2 * g;
            else return 2 * g - 1;
        }
    }
    int t1 = getans(r - 1, 2 * g - 1);
    int t2 = getans(r - 1, 2 * g);
    if(d[r][g] == 0){
        if(a[t1] >= r) return t1;
        else return t2;
    }
    else{
        if(a[t2] >= r) return t2;
        else return t1;
    }
}

signed main(){
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++ i)
        cin >> base[i];
    for(int i = 1; i <= m; ++ i)
        cin >> c[i];
    
    int k = log2(n);
    if((1 << k) != n) k++;

    for(int i = 1; i <= k; ++ i){
        string s;
        cin >> s;
        for(int j = 0; j < s.size(); ++ j)
            d[i][j + 1] = s[j] - '0';
    }
    
    int T;
    cin >> T;
    while(T --){
        int xxx[4];
        cin >> xxx[0] >> xxx[1] >> xxx[2] >> xxx[3];
        for(int i = 1; i <= n; ++ i)
            a[i] = base[i] ^ xxx[i % 4];
        
        

    }

    return 0;
}